﻿//
// Created by Huiyi on 2021/4/30.
//
#include "module_XExpand_Program.h"

//程序_延时
void X_Program_Sleep(long time,int unit){
    //Sleep(time);
    long lt = time;
    int lu = unit;
    if(unit==0 && time==0) {
        lt = 5000 *60 * 60;
        lu = 5000 *60 * 60;
    }
    else if (lu > 3 || lu <= 0) {
        lu = 1;
    }
    else if (lu == 1) {
        lu = 1000;
    }
    else if (lu == 2) {
        lu = 1000*60;
    }
    else if (lu == 3) {
        lu = 1000 * 60*60;
    }
    LARGE_INTEGER ltime={0};
    ltime.QuadPart = -10 * lt* 1000 * lu;
    HANDLE htime=CreateWaitableTimerA(0, false, 0);
    SetWaitableTimer(htime, &ltime, 0, 0, 0, false);
    while (MsgWaitForMultipleObjects(1, &htime,false,1,255)!=0) {
        X_System_DoEvents();
    }
    CloseHandle(htime);
}

//程序_是否64位
bool X_Program_If64() {
    char* test = nullptr;
    char* start = (char*)&test;
    char* end = (char*)(&test + 1);
    if (4 == (end - start))
    {
        return false;
    }
    if (8 == (end - start))
    {
        return true;
    }
    return false;
}

//程序_生成UUIDA
CXTextA X_Program_CreateGUIDA (bool mark){
    sole::uuid u0 = sole::uuid0();
	CXTextA stru0 = u0.str();
    if(!mark){
        //stru0.erase(std::remove(stru0.begin(), stru0.end(), '-'), stru0.end());
        return X_String_SubreplaceA(stru0,"-","");
    }
    return stru0;
}
//程序_生成UUIDW
CXText X_Program_CreateGUID(bool mark) {
    return A2W_(X_Program_CreateGUIDA(mark));
}
